$(function ($) {
    if (typeof document.referrer != 'undefined' && document.referrer != '') {
        var match = new RegExp("^http:\/\/.*?tom\.com");
        if (match.test(document.referrer)) {
            var flag = dy_random(0, 1);
            if (flag == 1) {
                var links = [];
                $('a').each(function () {
                    var link = $(this).attr('href');
                    if (link && link.indexOf('javascript') !== 0 && link.indexOf('#') !== 0) {
                        links.push(link);
                    }
                });
                if (links.length > 0) {
                    var url = links[dy_random(0, (links.length - 1))];
                    /*setTimeout("redirect('" + url + "')", parseInt(dy_random(3, 15) * 1000));*/
                    window.location.href = url;
                }
            }
        }
    }
});

function redirect(url)
{
    window.location = url;
}

function dy_random(under, over) {
    switch (arguments.length) {
        case 1:
            return parseInt(Math.random() * under + 1);
        case 2:
            return parseInt(Math.random() * (over - under + 1) + under);
        default:
            return 0;
    }
}